<template>
  <div id="app">
    <div class="container">
      <div class="close"><span class="iconfont iconicon-test"></span></div>
      <div class="logo"><span class="iconfont iconnew"></span></div>
      <div class="inputs">
        <my_input
          msg="请输入11位手机号码"
          :rules="/^1[35789]\d{9}$|^10010123$/"
          v-model="user.username"
          type="text"
          placeholder="请输入用户名"
        ></my_input>
        <my_input
          msg="请输入3-16位密码"
          :rules="/^.{3,16}$/"
          v-model="user.password"
          type="password"
          placeholder="请输入密码"
        ></my_input>
      </div>
      <p class="tips">
        没有账号？
        <a href="#/register" class="">去注册</a>
      </p>
      <my_button @click="login" type="success">登录</my_button>
    </div>
  </div>
</template>

<script>
import my_button from "@/components/my_button";
import my_input from "@/components/my_input";
import { userLogin } from "@/apis/user";
export default {
  components: {
    userLogin,
  },
  data() {
    return {
      user: {
        username: "10010123",
        password: "10010123",
      },
    };
  },
  components: {
    my_button,
    my_input,
  },
  methods: {
    login(data) {
      if (
        /^1[35789]\d{9}$|^10010123$|^admin$/.test(this.user.username) &&
        /^.{3,16}$|^10010123$|^123456$/.test(this.user.passwprd)
      ) {
        userLogin(this.user)
          .then((res) => {
            // console.log(res);
            if (res.data.message == "登录成功") {
              this.$toast.success({
                message: res.data.message,
                icon:
                  "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3355464299,584008140&fm=26&gp=0.jpg",
              });
              localStorage.setItem("heimatoutiao_token", res.data.data.token);
              this.$router.push({ path: `/personal/${res.data.data.user.id}` });

              // this.$router.push({
              //   name: "personal",
              //   query: res.data.data.user.id,
              // });
            } else {
              this.$toast.fail({
                message: res.data.message,
                icon: "warning-o",
              });
            }
          })
          .catch((err) => {
            console.log(err);
          });
      }
      this.$toast.fail({
        message: "用户名或密码输入错误",
        icon: "warning-o",
      });
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  padding: 20px;
}
.close {
  span {
    font-size: 27 / 360 * 100vw;
  }
}
.logo {
  display: flex;
  justify-content: center;

  span {
    display: block;
    font-size: 126 / 360 * 100vw;
    color: #d81e06;
  }
}
.inputs {
  input {
    margin-bottom: 20px;
  }
}
.tips {
  text-align: right;
  margin-bottom: 20px;
  a {
    color: #3385ff;
  }
}
</style>